package com.amsp.oa.oademo.controller;

import com.amsp.oa.oademo.entity.ProductInventory;
import com.amsp.oa.oademo.service.ProductInventoryService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/product-inventory")
@CrossOrigin
@Api(tags = "成品入库单")
public class ProductInventoryController {

    @Autowired
    private ProductInventoryService productInventoryService;

    @PostMapping("/save")
    @ApiOperation("保存成品入库单")
    public boolean save(@RequestBody ProductInventory productInventory) {
        return productInventoryService.saveWithItems(productInventory);
    }

    @GetMapping("/list")
    @ApiOperation("分页查询成品入库单")
    public Page<ProductInventory> list(
            @RequestParam(defaultValue = "1") Integer current,
            @RequestParam(defaultValue = "10") Integer size) {
        return productInventoryService.getPage(current, size);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据ID查询成品入库单")
    public ProductInventory getById(@PathVariable Long id) {
        return productInventoryService.getDetailById(id);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("根据ID删除成品入库单")
    public boolean delete(@PathVariable Long id) {
        return productInventoryService.removeById(id);
    }
}